#ifndef brick_gold_h
#define brick_gold_h

#include "StaticObject.h"

#define brickGoldWIDTH 45
#define brickGoldHEIGHT 45
#define BrickGold_ANIMATE_RATE 5
class BrickGold : public StaticObject
{
private:
	Sprite *_normalSprite;
	AnimatedSprite *_goldSprite;
	DWORD last_time;
	int _count;
	bool _add;

public:
	BrickGold(int id, D3DXVECTOR2 position, int MovingWidth): StaticObject(id, position, MovingWidth)
	{
		_w = brickGoldWIDTH;
		_h = brickGoldHEIGHT;
		_type = BrickGoldType;
		_movingWidth = MovingWidth;
		_count = 0;
		_add = false;
	}
	~BrickGold(){}
	void Update(int Delta)
	{
		if(!_add && flagCall)
		{
			if(_count<5)
			{
				DWORD now = GetTickCount();
				if (now - last_time > 1000 / BrickGold_ANIMATE_RATE)
				{
					_goldSprite -> Next();
					_count += 1;
					last_time = now;
				}
			}
			else _add = true;
		}
	}
	void LoadResources(LPD3DXSPRITE SpriteHandler, Texture *texture)
	{
		_normalSprite = new Sprite(SpriteHandler, texture, brickGoldWIDTH, brickGoldHEIGHT, 3, 0);
		_goldSprite = new AnimatedSprite(SpriteHandler, texture, brickGoldWIDTH, brickGoldHEIGHT, 5, 3, 1);
	}
	void RenderFrame(LPDIRECT3DSURFACE9 BackBuffer, ViewPort *viewport)
	{
		_normalSprite -> Render(BackBuffer, (int)_position.x, (int)_position.y, 255, 1, 1, viewport);
		if(flagCall && !_add)
		{
			_goldSprite -> Render(BackBuffer, (int)_position.x , (int)_position.y + brickGoldHEIGHT, 255, 1, 1, viewport);
		}
	}
};
#endif